package org.zhadoop.stream.cql.semanticanalyzer.parser.visitor;

import java.util.Locale;

import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.ColumnNameTypeListContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.CommentContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.ParallelClauseContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.SerdeClassContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.SerdePropertiesContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.SourceClauseContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.SourcePropertiesContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.StreamNameContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.context.CreateInputStatementContext;

/**
 * create input stream 语法遍历
 * @author zwd
 *
 */
public class CreateInputStreamVisitor extends AbsCQLParserBaseVisitor<CreateInputStatementContext> {
	
	private CreateInputStatementContext context = null;
	
	public CreateInputStreamVisitor() {
		context = new CreateInputStatementContext();
	}
	
	@Override
	protected CreateInputStatementContext defaultResult() {
		return context;
	}
	
	@Override
	public CreateInputStatementContext visitStreamName(StreamNameContext ctx) {
		context.setStreamName(ctx.getText().toLowerCase(Locale.US));
		return context;
	}
	
	@Override
	public CreateInputStatementContext visitColumnNameTypeList(ColumnNameTypeListContext ctx) {
		ColumnNameTypeListVisitor visitor = new ColumnNameTypeListVisitor();
		context.setColumns(visitor.visit(ctx));
		return context;
	}
	
	@Override
	public CreateInputStatementContext visitComment(CommentContext ctx) {
		// 忽略注释
		return context;
	}
	
	
	@Override
	public CreateInputStatementContext visitSerdeClass(SerdeClassContext ctx) {
		ClassNameVisitor visitor = new ClassNameVisitor();
		context.setDeserClassName(visitor.visit(ctx));
		return super.visitSerdeClass(ctx);
	}
	
	@Override
	public CreateInputStatementContext visitSerdeProperties(SerdePropertiesContext ctx) {
		StreamPropertiesVisitor visitor = new StreamPropertiesVisitor();
		context.setDeserProperties(visitor.visit(ctx));
		return context;
	}
	
	@Override
	public CreateInputStatementContext visitSourceClause(SourceClauseContext ctx) {
		ClassNameVisitor visitor = new ClassNameVisitor();
		context.setSourceClassName(visitor.visit(ctx));
		return context;
	}
	
	@Override
	public CreateInputStatementContext visitSourceProperties(SourcePropertiesContext ctx) {
		StreamPropertiesVisitor visitor = new StreamPropertiesVisitor();
		context.setSourceProperties(visitor.visit(ctx));
		return context;
	}
	
	@Override
	public CreateInputStatementContext visitParallelClause(ParallelClauseContext ctx) {
		ParallelClauseVisitor visitor = new ParallelClauseVisitor();
		context.setParallelNumber(visitor.visit(ctx));
		return context;
	}
}
